﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DAL;

namespace PeisongWeb.admin
{
    public partial class admin_popedom : adminPage
    {
        protected int cusId
        {
            get
            {
                int tmp;
                try { tmp = Convert.ToInt32(ViewState["adminid"]); }
                catch { tmp = 0; }
                return tmp;
            }
            set
            { ViewState["adminid"] = value; }
        }

        //protected void Page_Load(object sender, EventArgs e)
        //{
        //    if (!IsPostBack)
        //    {

        //        //rpt_list.DataSource = DAL.DbHelper.ExecuteSqlDataTable("select * from customer");
        //        //rpt_list.DataBind();
        //    }
        //}

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                if (Request.QueryString["admin"] != null)
                {
                    if (Library.Number.IsIntPositive(Request.QueryString["admin"]))
                    {
                        cusId = Convert.ToInt32(Request.QueryString["admin"]);
                    }
                }

                //hasPermission("",
                rptBind();
            }

        }

        private void rptBind()
        {
            
            DataTable dt = logic.sysPermission.list(cusId);
            if (dt.Rows.Count > 0)
            {
                rpt_list.DataSource = dt;
                rpt_list.DataBind();
            }
            else
            {
                Library.Script.ClientMsgUrl("无效的用户","adminList.aspx");
                return;
            
            }

            lbl_SysAdminName.Text = logic.sysAdmin.getById(cusId).Username;
            //string val_popedom = logic.admin.getById(adminid).popedom;
            //hid_Popedom.Value = val_popedom != null ? val_popedom : "";


        }

        protected void bt_save_Click(object sender, EventArgs e)
        {
            //logic.admin.setPopedom(adminid, hid_Popedom.Value);
            


            logic.sysAdmin.updatePermission(cusId, hid_Popedom.Value);
            Library.Script.ClientMsgUrl("权限设置成功!", "sysAdminList.aspx");

        }
    }
}
